<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    div {
      width: 300px;
      height: 40px;
      text-align: center;
      line-height: 40px;
      border: 1px solid blue;
    }
  </style>
</head>

<body>
  <div></div>
  <script>
    const div = document.querySelector('div')
    // 得到日期对象
    const date = new Date()
    div.innerHTML = date.toLocaleString() //2025/4/2 08:53:29
    setInterval(function () {
      const date = new Date()
      div.innerHTML = date.toLocaleString()
    }, 1000)
    // div.innerHTML = date.toLocaleDateString()  //2025/4/2
    // div.innerHTML = date.toLocaleTimeString()  //08:52:27
  </script>
</body>

</html>